import 'package:dio/dio.dart';
import 'package:flustars/flustars.dart';
import 'package:flutter_getx/app/config/constant.dart';
import 'package:flutter_getx/core/utils/device_utils.dart';

import 'getx/app_life_cycle_delegate.dart';
import 'net/dio_utils.dart';
import 'net/intercept.dart';
import 'utils/log_utils.dart';

Future<void> startInit() async {

  await SpUtil.getInstance();

  await Device.initDeviceInfo();

  LogPrint.init();

  initDio();

  AppLifeCycleDelegate();

}

void initDio() {
  final List<Interceptor> interceptors = <Interceptor>[];

  /// 统一添加身份验证请求头
  interceptors.add(AuthInterceptor());

  /// 打印Log(生产模式去除)
  if (!Constant.inProduction) {
    interceptors.add(LoggingInterceptor());
  }

  /// 适配数据(根据自己的数据结构，可自行选择添加)
  interceptors.add(AdapterInterceptor());

  configDio(
    baseUrl: Constant.inProduction
        ? 'http://193.134.208.251:8006/'
        : 'http://193.134.208.251:8006/',
    interceptors: interceptors,
  );
}